package com.zmm.common.base.model;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 900045
 * @description:
 * @name ResultCode
 * @date By 2021-06-22 10:15:58
 */
public enum ResultCode implements ResponseCode {

	/**
	 * 错误码和错误信息定义类
	 * 1.错误码定义规则为 6位数
	 * 2.前面两位表示业务场景,最后四位表示错误码. 例如 100001. 10: 通用 0001: 系统未知异常
	 * 3.维护错误码后需要维护错误信息
	 * 错误码列表:
	 * 	10: 通用
	 * 		0001: 系统未知异常
	 * 		0002: 操作失败
	 * 		0003: ....
	 * 	11:商品
	 * 	12:订单
	 * 	13:购物车
	 * 	14:物流
	 * 	15:用户
	 * 	16:佣金
	 * 	17:索引
	 * 	18.文章
	 * 	19.后台管理
	 * 	20.短信
	 * 	21.文件
	 * 	22.提现
	 * 	23.地址
	 */
	
	FAIL(000000, "系统异常，请刷新后重试"),
	SUCCESS(100000, "成功"),
	REQUEST_SUCCESS(100001, "操作请求成功，操作结果请稍后刷新查询"),
	METHOD_CALL_PARAMETER_ERROR(100002, "请求参数有误 请按照规则填写"),
	PARAMETER_ERROR(100003, "参数错误"),
	NOT_LOGGED(100004, "未登录,请登录后操作"),
	SERVICE_UPGRADE(100006, "服务升级中，请稍候再试"),
	REMOTE_SERVICE_FAIL(100007,"远程服务调用失败"),
	
	
	RECORD_ALREADY_EXISTS(100010, "记录已存在"),
	FIELD(100011, "操作失败!"),
	NULL_PARAMETER(100012, "空参"),
	INSERT_FAILED(100013,"新增失败"),
	UPDATE_FAILED(100014,"更新失败"),
	DELETE_FAILED(100015,"删除失败(伪)"),

	DISCOUNT_STOCK_EXCEPTION(120001,"扣减库存异常"),

	WARE_NULL_POINT_EXCEPTION(120002,"仓库为空异常"),

	LOCK_STOCK_EXCEPTION(120003,"锁库存异常"),

	USER_VERIFY_CODE_EXPIRE(150000, "验证码错误，请重新发送"),
	USER_PHONE_ALREADY_REGISTER_EXPIRE(150001, "该手机号已被注册"),
	REGISTER_EXPIRE(150002, "注册失败"),
	USERNAME_LOGIN_DISABLED(150003, "登录已锁定，请30分钟后再次尝试登录"),
	USER_NOT_EXIST(150004, "会员不存在"),
	PASSWORD_ERROR(150005, "账号名或密码错误"),
	PASSWORD_VERIFY_CODE_MEANTIME_NULL_ERROR(150006, "密码和验证码不能同时为空"),
	PASSWORD_VERIFY_CODE_MEANTIME_NOT_NULL_ERROR(150007, "密码和验证码不能同时不为空"),
	USER_PHONE_NOT_NULL_EXPIRE(150008, "手机号码不能为空"),
	USER_PHONE_ERROR_EXPIRE(150009, "手机号格式不正确"),
	USER_TOKEN_NOT_NULL_EXPIRE(150008, "token不能为空"),
	VERIFY_CODE_TOKEN_EXPIRY(150009, "验证码令牌失效"),
	USER_REGISTRY_EXPIRE(150010, "注册失败"),
	USER_NOT_LOGIN(150011,"用户未登录"),


	USER_ADDRESS_TOO_LONG(230000, "收货地址长度超出限制"),
	CONSIGNEE_LENGTH_TOO_LONG(230001,"收件人长度超出限制"),
	ADDRESS_REGION_INVALID(230002, "收货地址区域无效"),
	CUSTOMER_ADDRESS_UPDATE_FAIL(230003, "用户地址更新失败"),
	CUSTOMER_ADDRESS_INSERT_FAIL(230004, "用户地址新增失败"),

	BULK_SAVE_INDEX_FAIL(170006,"批量保存索引失败"),
	;
	
	/**
	 * 编码
	 */
	private Integer code;

	/**
	 * 中文描述
	 */
	private String desc;


	/**
	 * 返回码MAP
	 */
	private static Map<Integer, ResponseCode> map;


	static {
		// 初始化
		map = new HashMap<>();
		for (ResultCode code : ResultCode.values()) {
			map.put(code.getCode(), code);
		}
	}

	ResultCode(int code, String desc) {
		this.code = code;
		this.desc = desc;
	}

	public static ResponseCode getType(int code) {
		if (code <= 0) {
			return null;
		}
		return map.get(code);
	}


	@Override
	public Integer getCode() {
		return code;
	}

	@Override
	public boolean print() {
		return false;
	}

	@Override
	public String getDesc() {
		return desc;
	}
}
